package com.sky.controller.user;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import com.sky.service.common.MerchantService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * C端: 店铺状态控制器层
 * @author zgp
 * @version V1.0
 * @date 2025-01-20 19:53
 */
@Api(tags = "店铺相关接口")
@RestController("userShopController")
@RequestMapping("/user/shop")
@Slf4j
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MerchantService merchantService;

    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
        log.info("获取店铺营业状态，status：{}", status == 1 ? "营业中" : "打烊中");
        return Result.success(status);
    }

    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result<ShopVO> getMerchantInfo(){
        log.info("获取商家信息.");
        return Result.success(merchantService.getMerchantInfo(1L));
    }
}
